package com.yjjxt

import org.apache.spark.{SparkConf, SparkContext}

object Hello16MapPartitionWithIndex {

  def main(args: Array[String]): Unit = {

    val sparkContext = new SparkContext((new SparkConf().setMaster("local").setAppName("Join" + System.currentTimeMillis())))

    val array1 = Array[String]("Hello1 user1", "Hello2 user1", "Hello user11", "Hello user12", "user1 apple1")
    val lines1 = sparkContext.parallelize(array1, 3)

    lines1.mapPartitionsWithIndex((idx, iter) => {
      //遍历一下
      while (iter.hasNext) {
        println(idx + "--" + iter.next())
      }
      iter
    }).count()

    sparkContext.stop

  }
}
